package controller;

import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import service.UserService;

import java.util.List;

@Controller
public class HelloController {
    @Autowired
    UserService userService;

    @GetMapping("/hello")
    public String hello(Model model){

        model.addAttribute("name","xyz");
        model.addAttribute("url","http://www.xyz.com");
        return "hello";
    }

    @GetMapping("/userlist")
    public String userlist(Model model){

        List<User> userInfos = userService.listUsers();
        for (User u:userInfos) {
            System.out.println(u.toString());
        }
        model.addAttribute("userInfos",userInfos);
        return "userlist";
    }
}
